# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=libpg_query
# Keep in mind the aport ruby-pg_query when bumping.
pkgver=15.4.2.3
_pkgver=${pkgver/./-}
pkgrel=0
pkgdesc="C library for accessing the PostgreSQL parser outside of the server"
url="https://github.com/pganalyze/libpg_query"
# riscv64: broken, "unknown type name 'slock_t'"
arch="all !riscv64"
license="BSD-3-Clause"
makedepends="protobuf-c-dev xxhash-dev"
subpackages="$pkgname-dbg $pkgname-dev"
source="https://github.com/pganalyze/libpg_query/archive/$_pkgver/$pkgname-$_pkgver.tar.gz
	dont-override-opt-level.patch
	verbose-build.patch
	unbundle-vendor-deps.patch
	"
builddir="$srcdir/$pkgname-$_pkgver"

prepare() {
	default_prepare

	# Remove vendored libraries.
	rm -Rf vendor
}

build() {
	make build build_shared
}

check() {
	case "$CARCH" in
		# XXX: Ignore errors on 32bit arches,
		#  see https://github.com/pganalyze/libpg_query/issues/158
		armhf | armv7 | x86) make test || true;;
		*) make test;;
	esac
}

package() {
	make install DESTDIR="$pkgdir" prefix=/usr
}

sha512sums="
7998982ea000505a65f564ba360191ae356fd0f29ad9414b7203f1275ebf1a9679cba3a9e69418a4c31aa65de5ff4ed7f113d5c3511d386847a385635990f05b  libpg_query-15-4.2.3.tar.gz
a3ddc483b23cd25c24c05668f721aa4bb0e862524512078ca4b851c4e7442e4ae3a20dcf20ab8e81fe112eaf35c4866011ad75368172304050c5607967eab2ed  dont-override-opt-level.patch
ccb32f6b2ba62248a995a2022f6a676b5c664adfd1c7073e706876dd58842dfff770b98b8a811734f0852f215f7d67401111900b5ce2421e2cce2b9c5c329fec  verbose-build.patch
70c0bbc29fcf6e035dd0de04a0cc1bee366c29d8a849f83799d334b7fb8ac823acf753c0c280663e8ad7a07f9ac976ff5ceccfa0f7ba1e0eb9b5cfd4c947d2f0  unbundle-vendor-deps.patch
"
